#ifndef _PROXYCLIENT_SERVICE_H_
#define _PROXYCLIENT_SERVICE_H_

#include "proxy_head.h"
#include "common_define.h"
#include "jsonmessage.h"
#include "common_singleton.h"
#include "proxy_client.h"
#include "object.h"
#include "client_net_new.h"
#include "server_base.h"
#include "client_base.h"
//#include "gate_transfer_server.h"


class CProxyClientService 
	:public ::common::CClientBase 
	,public ::common::CSingleton< CProxyClientService >
{
public:
	CProxyClientService();

	~CProxyClientService( );

	virtual int32_t InitializeServer( int service_type, int service_id, IService* server);
	virtual int32_t Finalize( );

	int SendMsg2Game( uint32_t msg_id, const std::string& msg, int32_t area_id = 0, int server_id = 0 );
	int SendMsg2Map(uint32_t msg_id, const std::string& msg, int32_t area_id = 0);
	int SendMsg2Chat(uint32_t msg_id, const std::string& msg, int32_t area_id = 0);
	int SendMsg2Gate( uint32_t msg_id, const std::string& msg, int area_id = 0 );
	int SendMsg2Login( uint32_t msg_id, const std::string& msg, int32_t area_id = 0 );
	int SendMsg2DB( uint32_t msg_id, const std::string& msg, int split/* = 0 */, int32_t area_id = 0 );
	int SendMsg2Log( uint32_t msg_id, const std::string& msg, int split/* = 0 */, int32_t area_id = 0 );
	int SendMsg2Match( uint32_t msg_id, const std::string& msg );
    int SendMsg2Proxy( uint32_t msg_id, const std::string& msg );
	int SendMsg2Platform(uint32_t msg_id, const std::string& msg);
	int SendResponseMsg( const common::CProxyHead& src_head, uint32_t msg_id, const std::string& msg );
	virtual int32_t SendMsg(common::CProxyHead& proxy_head, const std::string& msg);

	int SendServiceMsg( uint32_t msg_id, const std::string& msg, uint32_t dst_area_id, uint32_t dest_server_type,
		uint32_t dest_server_id, OBJ_ID_TYPE session_id, int32_t extend, int32_t send_platform = 0 );

	void SendRegisterProxyService();
	void SendRegisterPlatformProxyService();

	OBJ_ID_TYPE AddSendSessionID( OBJ_ID_TYPE session_id );
	OBJ_ID_TYPE GetSendSessionID( );
	int ClearSendSessionID( );

	OBJ_ID_TYPE AddBackSessionID( OBJ_ID_TYPE session_id );
	OBJ_ID_TYPE GetBackSessionID( );
	int ClearBackSessionID( );

	void SetMapArea(uint32_t map_area);
    //void CheckPingTime( );
public:
	virtual bool on_msg(uint32_t id);
	virtual void OnConnect();

private:
	OBJ_ID_TYPE		send_service_msg_session_id_;
	OBJ_ID_TYPE 	back_service_msg_session_id_;

	//CClientNet*		client_net_;
	IService*		service_;
	//std::string		ip_;
	//uint16_t		port_;

	uint32_t		map_area_;
};
#define BROADCAST_GATEWAY_ID		(~0)
//#define registe_session				common::CProxyClientService::GetInstance( ).RegisteSessionCallback
//#define registe_server_msg			common::CProxyClientService::GetInstance( ).RegisteServerCallback
#define set_send_session			CProxyClientService::GetInstance( ).AddSendSessionID
#define set_back_session			CProxyClientService::GetInstance( ).AddBackSessionID

#define send_2_game 				CProxyClientService::GetInstance( ).SendMsg2Game
#define send_2_map 					CProxyClientService::GetInstance( ).SendMsg2Map
#define send_2_chat 				CProxyClientService::GetInstance( ).SendMsg2Chat
#define send_2_gate					CProxyClientService::GetInstance( ).SendMsg2Gate
#define send_2_login				CProxyClientService::GetInstance( ).SendMsg2Login
#define send_2_db					CProxyClientService::GetInstance( ).SendMsg2DB
#define send_2_log					CProxyClientService::GetInstance( ).SendMsg2Log
#define send_2_match                CProxyClientService::GetInstance( ).SendMsg2Match
#define send_2_proxy                CProxyClientService::GetInstance( ).SendMsg2Proxy
#define send_response_msg			CProxyClientService::GetInstance( ).SendResponseMsg
#define send_2_platform				CProxyClientService::GetInstance( ).SendMsg2Platform

#endif

